﻿function Path(stringPath) {
    var match = stringPath.match(/__[a-zA-Z0-9]+$/);
    this.stringPath = stringPath;
    if (match) {
        this.functor = match[0].substring(2);
        this.stringPathParts = this.stringPath.substring(0, this.stringPath.length - match[0].length);
    } else {
        this.stringPathParts = this.stringPath;
    }
}

Path.getSiblingId = function(id, index) {
    if (index == null || index == 0) index = 1;
    if (index == -1) index = '';
    var underscoreIndex = id.lastIndexOf("_");
    return id.substring(0, underscoreIndex) + "_" + index;
}

Path.prototype = {    

    isNodePath: function() {
        return (this.functor == null);
    },

    getNodePath: function() {
        return this.stringPathParts;
    },

    getPrototypePath: function() {
        return this.stringPathParts.replace(/_(\d+)/g, "_0");
    },

    getString: function() {
        return this.stringPath;
    }
}

